package ru.braim.weather_app.utils.validators.models;

import ru.braim.weather_app.dto.weather_forecast.WeatherForecastRequestDTO;
import ru.braim.weather_app.models.WeatherForecast;
import ru.braim.weather_app.models.enums.WeatherCondition;

public class WeatherForecastValidator {

    public static WeatherForecast getValidWeatherForecast(WeatherForecastRequestDTO weatherForecastRequestDTO) {
        try {
            WeatherForecast weatherForecast = new WeatherForecast();

            if (weatherForecast.setLocalDateTime(weatherForecastRequestDTO.getDateTime()) &&
                    weatherForecastRequestDTO.getRegionId() != null && weatherForecastRequestDTO.getRegionId() > 0 &&
                    WeatherCondition.getWeatherCondition(weatherForecastRequestDTO.getWeatherCondition()) != null
            ) {
                weatherForecast.setTemperature(weatherForecastRequestDTO.getTemperature());
                weatherForecast.setWeatherCondition
                        (WeatherCondition.getWeatherCondition(weatherForecastRequestDTO.getWeatherCondition()));
                return weatherForecast;
            }

            return null;
        } catch (Exception e) {
            return null;
        }
    }

}
